package com.cskaoyan.controller.admin;

import com.cskaoyan.bean.entity.Admin;
import com.cskaoyan.bean.entity.Storage;
import com.cskaoyan.bean.vo.BasePageData;
import com.cskaoyan.bean.vo.BaseParam;
import com.cskaoyan.bean.vo.BaseRespVo;
import com.cskaoyan.bean.vo.StorageCommonVo;
import com.cskaoyan.service.AdminService;
import com.cskaoyan.service.AdminServiceImpl;
import com.cskaoyan.service.UserService;
import com.cskaoyan.utils.BaseRespVoUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

@RestController
@RequestMapping("admin/admin")
public class AdminController {

    /**
     * 管理员
     *
     * admin/admin/
     *
     * list,create,update,delete
     */
    @Autowired
    AdminService adminService;


    @RequestMapping("list")//handler方法url  请求参数  我需要的响应参数是什么
    public BaseRespVo list(String username, BaseParam param) {
        BasePageData data = adminService.query(username, param);
        return BaseRespVo.ok(data);
    }

    /**
     * <h2> 添加 管理员 </h2>
     */
    @PostMapping("create")
    public BaseRespVo create(@RequestBody Admin admin) {
        BasePageData data = adminService.create(admin);

        return BaseRespVo.ok(data);
    }

    /**
     * <h2> 修改 管理员 </h2>
     */
    @PostMapping("update")
    public BaseRespVo update(@RequestBody Admin admin) {
        BasePageData data = adminService.update(admin);

        return BaseRespVo.ok(data);
    }

    /**
     * <h2> 删除 管理员 </h2>
     */
    @PostMapping("delete")
    public BaseRespVo delete(@RequestBody Admin admin) {
        int data = adminService.delete(admin);

        return BaseRespVo.ok(data);
    }

}
